<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <!-- <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'imprest.add'"></el-button> -->
                <!-- <el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length == 0" @click="batch_del" v-auth="'custom.delete'"></el-button> -->
                <!-- <sc-file-import :apiObj="$API.order.entrust.orderUp" @success="success" ref="importBox" templateUrl="https://2156.mzth.cn/import.xlsx"></sc-file-import> -->
            </div>
            <div class="right-panel">
                <div class="right-panel-search" style="flex-wrap:wrap;">
                    <el-date-picker v-model="search.year" :value-format="'YYYY'" type="year" placeholder="年份" style="width: 230px" />
                    <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh">重置</el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" @selection-change="selectionChange" remoteSort remoteFilter border hidePagination hideDo>
                <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                <el-table-column label="月份" prop="month" align="center"></el-table-column>
                <el-table-column label="申请总额合计" prop="apply_money" align="center"></el-table-column>
                <el-table-column label="已核销金额合计" prop="verification_money" align="center"></el-table-column>
                <el-table-column label="未核销金额合计" prop="not_verification_money" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="210">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_detail(scope.row, scope.$index)">查看</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <detail-save v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false" :query="{month: month}"></detail-save>
</template>

<script>
import DetailSave from './detailSave.vue'

export default {
	name: '客户管理',
	components: { DetailSave },
	data() {
		return {
			dialog: {
				save: false,
			},
			apiObj: this.$API.project.Imprest.list_year,
			selection: [],
			search: {
				year: null,
			},
            month:"",
		}
	},
	mounted() {
	},
	methods: {
		//详情
		table_detail(row) {
            this.month = row.month
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit')
			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
	}
}
</script>

<style>
.titleBox {
	font-size: 14px;
	font-weight: 500;
	color: #0099ff;
	margin-left: 30px;
}
</style>
